import pymysql

def readWord():
    f = open('word','r',encoding='utf-8')
    words = f.read().split('***********************************************************************')

    f.close()
    return words

def main():
    import pymysql
    db = pymysql.connect(
        host="",
        port=3306,
        user='spider',    #在这里输入用户名
        password='',     #在这里输入密码
        charset='utf8',
        database='spider'
        )

    cursor = db.cursor() #创建游标对象
    words =readWord()
    for  word in words:
        if len(word)>2:
            sql="INSERT INTO `weibo_word` (`word`) VALUES('"+word+"');"
            print(sql)
            try:
                res = cursor.execute(sql)
            except:
                pass


# main()

# peewee orm 数据库操作
import peewee
from peewee import *
def test():

    db = MySQLDatabase('spider', user='root',passwd='root')

    class Book(peewee.Model):
        author = CharField()
        title = TextField()

        class Meta:
            database = db

    res =Book.create_table()
    print(res)
    # book = Book(author="me", title='Peewee is cool')
    # book.save()

    book = Book()
    book.author='tsm'
    book.title='ssss'
    book.save()
    # for book in Book.filter():
    #     print(book.title)
    s=Book.get_by_id(5)
    print(s.title)

test()



